<template>
  <div>
    <el-form class="f">
      <v-form-title title="基本注册信息"/>
      <el-form-item label="用户名">
          <span v-if="!isEdit">{{userInfo.username}}</span>
          <el-button type="text" size="mini" class="iconfont icon-bianji" @click="edit(0)" v-if="!isEdit"></el-button>
          <el-col :span="6" v-if="isEdit">
            <el-input v-model="userInfo.username" class="line-input"></el-input>
          </el-col>
          <el-button type="primary" size="mini" @click="edit(1)" v-if="isEdit">完成</el-button><!--  :disabled="!userName || userName == userInfo.username" -->
      </el-form-item>
      <el-form-item label="手机号码">{{userInfo.phone}}</el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
  import { Vue, Component, Prop } from 'vue-property-decorator'
  import vFormTitle from '@/components/form-title'
  import { Mutation } from 'vuex-class'
  @Component({
    components: {
      vFormTitle
    }
  })
  export default class Base extends Vue {
    @Prop() userInfo
    @Mutation removeUserInfo
    //@Getter userInfo
    isEdit = false
    userName = ''

    async edit (mode) {
      if (mode === 1) {
        this.changeName(this.userName)
      }
      this.isEdit = !this.isEdit;
    }

    async changeName (f) {
      let res: AjaxResponse = await this.$axios.post('g/gateway/channelprovider/changeuname', {
        userName: f
      })
      this.removeUserInfo()
      this.$router.push('/login')
      this.$utils.tips(res) 
    }
    mounted () {
      //this.userName = this.userInfo.username
      console.log(this.userInfo.username)
    }
  }
</script>

<style lang="less" scoped>
  .f {
    width: 1180px;
    margin: 0 auto;
    padding-top: 60px;
  }

</style>
